package personal.scanner;

import exceptions.IllegalDecimalException;
import exceptions.IllegalIdentifierException;
import exceptions.IllegalSymbolException;

import java.util.List;

public interface MyScanner {


    List<Token> scan(String input) throws IllegalSymbolException, IllegalDecimalException, IllegalIdentifierException;


    /**
     * 词法单元
     */
    class Token {
        private final String expression;

        public String getExpression() {
            return expression;
        }

        protected Token(String lexeme) {
            this.expression = lexeme;
        }

        @Override
        public int hashCode() {
            return this.expression.hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null || this.getClass() != obj.getClass()) return false;
            return this.expression == ((Token) obj).expression;
        }

        @Override
        public String toString() {
            return String.format("%s: %s", this.getClass().getName(), this.getExpression());
        }
    }

    /**
     * 运算数
     */
    class OperandToken extends Token {

        protected OperandToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 运算符
     */
    class OperatorToken extends Token {

        protected OperatorToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 函数
     */
    final class FunctionToken extends Token {

        public FunctionToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 数字
     */
    final class DecimalToken extends OperandToken {

        public DecimalToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 布尔数
     */
    final class BooleanToken extends OperandToken {

        public BooleanToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 算术运算符
     */
    class ArithmeticOperatorToken extends OperatorToken {

        protected ArithmeticOperatorToken(String lexeme) {
            super(lexeme);
        }
    }


    /**
     * 逻辑运算符
     */
    class LogicalOperatorToken extends OperatorToken {

        protected LogicalOperatorToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 分隔符
     */
    final class DelimiterOperatorToken extends OperatorToken {

        public DelimiterOperatorToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 单目算术运算符
     */
    final class ArithmeticOperator1DToken extends ArithmeticOperatorToken {

        public ArithmeticOperator1DToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 双目算术运算符
     */
    final class ArithmeticOperator2DToken extends ArithmeticOperatorToken {

        public ArithmeticOperator2DToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 三目算术运算符
     */
    final class ArithmeticOperator3DToken extends ArithmeticOperatorToken {

        public ArithmeticOperator3DToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 比较运算符
     */
    final class CompareOperatorToken extends LogicalOperatorToken {

        public CompareOperatorToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 单目逻辑运算符
     */
    final class LogicalOperator1DToken extends LogicalOperatorToken {

        public LogicalOperator1DToken(String lexeme) {
            super(lexeme);
        }
    }

    /**
     * 双目逻辑运算符
     */
    final class LogicalOperator2DToken extends LogicalOperatorToken {

        public LogicalOperator2DToken(String lexeme) {
            super(lexeme);
        }
    }


}
